﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.ComponentModel.DataAnnotations;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using nERP.Model.Wms;
using nERP.Model;
using nERP.Model.So;
using nERP.Model.Bas;

namespace nERP.ViewModel.Wms.SaleReturnInWarehouseDetailVMs
{
    public partial class SaleReturnInWarehouseDetailListVM : BasePagedListVM<SaleReturnInWarehouseDetail_View, SaleReturnInWarehouseDetailSearcher>
    {

        protected override IEnumerable<IGridColumn<SaleReturnInWarehouseDetail_View>> InitGridHeader()
        {
            return new List<GridColumn<SaleReturnInWarehouseDetail_View>>{

                this.MakeGridHeader(x => x.SaleReturnInWarehouseDetail_Seq).SetTitle(@Localizer["Page.序号"].Value),
                this.MakeGridHeader(x => x.SaleReturnInWarehouseDetail_SaleReturnInWarehouse).SetTitle(@Localizer["Page.销售退货入库"].Value),
                this.MakeGridHeader(x => x.SaleReturnInWarehouseDetail_SaleReturnInWarehouseDetailCode).SetTitle(@Localizer["Page.销售退货入库明细单号"].Value),
                this.MakeGridHeader(x => x.SaleReturnInWarehouseDetail_SaleReturn).SetTitle(@Localizer["Page.销售退货"].Value),
                this.MakeGridHeader(x => x.SaleReturnInWarehouseDetail_SaleReturnDetail).SetTitle(@Localizer["Page.销售退货明细"].Value),
                this.MakeGridHeader(x => x.SaleReturnInWarehouseDetail_Warehouse).SetTitle(@Localizer["Page.仓库"].Value),
                this.MakeGridHeader(x => x.SaleReturnInWarehouseDetail_Goods).SetTitle(@Localizer["Page.商品"].Value),
                this.MakeGridHeader(x => x.SaleReturnInWarehouseDetail_GoodsName).SetTitle(@Localizer["Page.商品名称"].Value),
                this.MakeGridHeader(x => x.SaleReturnInWarehouseDetail_GoodsSpec).SetTitle(@Localizer["Page.商品规格"].Value),
                this.MakeGridHeader(x => x.SaleReturnInWarehouseDetail_GoodsUnit).SetTitle(@Localizer["Page.计量单位"].Value),
                this.MakeGridHeader(x => x.SaleReturnInWarehouseDetail_ReturnNumber).SetTitle(@Localizer["Page.退货入库数量"].Value),
                this.MakeGridHeader(x => x.SaleReturnInWarehouseDetail_Remark).SetTitle(@Localizer["_Admin.Remark"].Value),
                this.MakeGridHeader(x => x.SaleReturnInWarehouseDetail_Status).SetTitle(@Localizer["Page.状态"].Value),
                this.MakeGridHeader(x => x.SaleReturnInWarehouseDetail_CreateTime).SetTitle(@Localizer["_Admin.CreateTime"].Value),
                this.MakeGridHeader(x => x.SaleReturnInWarehouseDetail_UpdateTime).SetTitle(@Localizer["_Admin.UpdateTime"].Value),
                this.MakeGridHeader(x => x.SaleReturnInWarehouseDetail_CreateBy).SetTitle(@Localizer["_Admin.CreateBy"].Value),
                this.MakeGridHeader(x => x.SaleReturnInWarehouseDetail_UpdateBy).SetTitle(@Localizer["_Admin.UpdateBy"].Value),

                this.MakeGridHeaderAction(width: 200)
            };
        }


        public override IOrderedQueryable<SaleReturnInWarehouseDetail_View> GetSearchQuery()
        {
            var query = DC.Set<SaleReturnInWarehouseDetail>()

                .CheckEqual(Searcher.Seq, x => x.Seq)
                .CheckEqual(Searcher.SaleReturnInWarehouseId, x => x.SaleReturnInWarehouseId)
                .CheckContain(Searcher.SaleReturnInWarehouseDetailCode, x => x.SaleReturnInWarehouseDetailCode)
                .CheckEqual(Searcher.SaleReturnId, x => x.SaleReturnId)
                .CheckEqual(Searcher.SaleReturnDetailId, x => x.SaleReturnDetailId)
                .CheckEqual(Searcher.WarehouseId, x => x.WarehouseId)
                .CheckEqual(Searcher.GoodsId, x => x.GoodsId)
                .CheckContain(Searcher.GoodsName, x => x.GoodsName)
                .CheckContain(Searcher.GoodsSpec, x => x.GoodsSpec)
                .CheckContain(Searcher.GoodsUnit, x => x.GoodsUnit)
                .CheckEqual(Searcher.ReturnNumber, x => x.ReturnNumber)
                .CheckContain(Searcher.Remark, x => x.Remark)
                .CheckEqual(Searcher.Status, x => x.Status)
                .CheckBetween(Searcher.CreateTime?.GetStartTime(), Searcher.CreateTime?.GetEndTime(), x => x.CreateTime, includeMax: false)
                .CheckBetween(Searcher.UpdateTime?.GetStartTime(), Searcher.UpdateTime?.GetEndTime(), x => x.UpdateTime, includeMax: false)
                .CheckContain(Searcher.CreateBy, x => x.CreateBy)
                .CheckContain(Searcher.UpdateBy, x => x.UpdateBy)
                .Select(x => new SaleReturnInWarehouseDetail_View
                {
                    ID = x.ID,

                    SaleReturnInWarehouseDetail_Seq = x.Seq,
                    SaleReturnInWarehouseDetail_SaleReturnInWarehouse = DC.Set<SaleReturnInWarehouse>().Where(z0 => z0.SaleReturnInWarehouseCode == x.SaleReturnInWarehouseId).Select(y => y.SaleReturnInWarehouseCode).FirstOrDefault(),
                    SaleReturnInWarehouseDetail_SaleReturnInWarehouseDetailCode = x.SaleReturnInWarehouseDetailCode,
                    SaleReturnInWarehouseDetail_SaleReturn = DC.Set<SaleReturn>().Where(z0 => z0.SaleReturnCode == x.SaleReturnId).Select(y => y.SaleReturnCode).FirstOrDefault(),
                    SaleReturnInWarehouseDetail_SaleReturnDetail = DC.Set<SaleReturnDetail>().Where(z0 => z0.SaleReturnDetailCode == x.SaleReturnDetailId).Select(y => y.SaleReturnDetailCode).FirstOrDefault(),
                    SaleReturnInWarehouseDetail_Warehouse = DC.Set<Warehouse>().Where(z0 => z0.WarehouseCode == x.WarehouseId).Select(y => y.WarehouseName).FirstOrDefault(),
                    SaleReturnInWarehouseDetail_Goods = x.GoodsId,// DC.Set<Goods>().Where(z0 => z0.GoodsCode == x.GoodsId).Select(y => y.GoodsName).FirstOrDefault(),
                    SaleReturnInWarehouseDetail_GoodsName = x.GoodsName,
                    SaleReturnInWarehouseDetail_GoodsSpec = x.GoodsSpec,
                    SaleReturnInWarehouseDetail_GoodsUnit = x.GoodsUnit,
                    SaleReturnInWarehouseDetail_ReturnNumber = x.ReturnNumber,
                    SaleReturnInWarehouseDetail_Remark = x.Remark,
                    SaleReturnInWarehouseDetail_Status = x.Status,
                    SaleReturnInWarehouseDetail_CreateTime = x.CreateTime,
                    SaleReturnInWarehouseDetail_UpdateTime = x.UpdateTime,
                    SaleReturnInWarehouseDetail_CreateBy = x.CreateBy,
                    SaleReturnInWarehouseDetail_UpdateBy = x.UpdateBy,
                })
                .OrderBy(x => x.ID);
            return query;
        }


    }
    public class SaleReturnInWarehouseDetail_View : SaleReturnInWarehouseDetail
    {

        public int? SaleReturnInWarehouseDetail_Seq { get; set; }
        public string SaleReturnInWarehouseDetail_SaleReturnInWarehouse { get; set; }
        public string SaleReturnInWarehouseDetail_SaleReturnInWarehouseDetailCode { get; set; }
        public string SaleReturnInWarehouseDetail_SaleReturn { get; set; }
        public string SaleReturnInWarehouseDetail_SaleReturnDetail { get; set; }
        public string SaleReturnInWarehouseDetail_Warehouse { get; set; }
        public string SaleReturnInWarehouseDetail_Goods { get; set; }
        public string SaleReturnInWarehouseDetail_GoodsName { get; set; }
        public string SaleReturnInWarehouseDetail_GoodsSpec { get; set; }
        public string SaleReturnInWarehouseDetail_GoodsUnit { get; set; }
        public decimal? SaleReturnInWarehouseDetail_ReturnNumber { get; set; }
        public string SaleReturnInWarehouseDetail_Remark { get; set; }
        public dStatusTypeEnum? SaleReturnInWarehouseDetail_Status { get; set; }
        public DateTime? SaleReturnInWarehouseDetail_CreateTime { get; set; }
        public DateTime? SaleReturnInWarehouseDetail_UpdateTime { get; set; }
        public string SaleReturnInWarehouseDetail_CreateBy { get; set; }
        public string SaleReturnInWarehouseDetail_UpdateBy { get; set; }

    }

}